package com.yc.srping;

import com.yc.spring.BeanConfig;
import com.yc.spring.bean.User;
import org.junit.Assert;
import org.junit.Test;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

public class SpringTest2 {
    AnnotationConfigApplicationContext cxt =
            new AnnotationConfigApplicationContext(BeanConfig.class);

    @Test
    public void test1(){
        User user1 = (User) cxt.getBean("user1");
        Assert.assertEquals("张三", user1.getName());
        User user2 = (User) cxt.getBean("user2");
        User user3 = (User) cxt.getBean("user3");
        Assert.assertEquals(false, user2==user1);
        Assert.assertEquals(true, user2==user3);
        Assert.assertEquals("李四", user2.getName());

        // @Primary
        User user4 = cxt.getBean(User.class);
        Assert.assertEquals("张三", user4.getName());

        // @Scope
        User user1_1 = (User) cxt.getBean("user1");
        Assert.assertEquals(false, user1==user1_1);

        User user5 = (User) cxt.getBean("user4");
        Assert.assertEquals("凸轮月牙铲", user5.getWeapon().getName());
    }
}
